# -*- coding: utf-8 -*-
"""
@Author: Logan
@Date:   2025/6/28 15:15
@Description: 
"""
import datetime
import os

import requests


# 正确示例：返回字符串格式时间


def get_project_path() -> str:
    """
    获取项目目录
    :return:
    """
    project_name = 'trading_system_ui_autotest'
    project_path = os.path.dirname(__file__)
    # 字符串切割,获取项目绝对路径
    final_path = project_path[:project_path.find(project_name) + len(project_name)]
    return final_path


def sep(path, add_sep_before=True, add_sep_after=False) -> str:
    """
    拼接文件路径，添加路径分隔符
    :param path:路径列表，类型为列表
    :param add_sep_before:在路径前添加路径分隔符
    :param add_sep_after:在路径后添加系统分隔符
    :return:
    """
    all_path = os.sep.join(path)
    if add_sep_before:
        all_path = os.sep + all_path
    if add_sep_after:
        all_path = all_path + os.sep
    return all_path


def abs_path(pro_path, cur_path) -> str:
    return (pro_path + cur_path).replace("\\", "/")


def get_img_path(img_name):
    """
    获取商品图片的路径
    :return:
    """
    img_dir_path = get_project_path() + os.sep + "common" + os.sep + "img" + os.sep + img_name
    return img_dir_path


def get_now_date_time_str():
    return datetime.datetime.now().strftime("%Y%m%d%H%M%S")


def get_now_time():
    # 格式化为字符串，例如 "2025-07-14 15:30:00"
    return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")


def get_every_wallpaper():
    """
    从bing获取每日壁纸
    Returns:

    """
    everyday_wallpaper_url = "https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=10&mkt=zh-CN"
    try:
        res = requests.get(url=everyday_wallpaper_url)
        wallpaper_url = "https://cn.bing.com" + res.json()["images"][0]["url"][:-7]
    except Exception as e:
        print(e)
        wallpaper_url = "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2Ftp09%2F210F2130512J47-0-lp.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1660141794&t=23615f6a8b4ca7aa42662f53c93c7717"
    return wallpaper_url


if __name__ == '__main__':
    print(get_every_wallpaper())